package cn.h8k.hj212.starter.autoconfigure;

import cn.h8k.hj212.version.ProtocolVersion;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.HashMap;
import java.util.Map;

/**
 * HJ212协议编解码器属性配置类
 * 支持增强功能的完整配置
 * 
 * @author H8K Team
 * @since 1.0
 */
@ConfigurationProperties(prefix = "hj212")
public class Hj212Properties {
    
    /**
     * 缓存配置
     */
    private Cache cache = new Cache();
    
    /**
     * 验证配置
     */
    private Validation validation = new Validation();
    
    /**
     * 插件配置
     */
    private Plugin plugin = new Plugin();
    
    /**
     * 版本配置
     */
    private Version version = new Version();
    
    /**
     * 自定义属性
     */
    private Map<String, Object> custom = new HashMap<>();
    
    // Getter和Setter方法
    public Cache getCache() {
        return cache;
    }
    
    public void setCache(Cache cache) {
        this.cache = cache;
    }
    
    public Validation getValidation() {
        return validation;
    }
    
    public void setValidation(Validation validation) {
        this.validation = validation;
    }
    
    public Plugin getPlugin() {
        return plugin;
    }
    
    public void setPlugin(Plugin plugin) {
        this.plugin = plugin;
    }
    
    public Version getVersion() {
        return version;
    }
    
    public void setVersion(Version version) {
        this.version = version;
    }
    
    public Map<String, Object> getCustom() {
        return custom;
    }
    
    public void setCustom(Map<String, Object> custom) {
        this.custom = custom;
    }
    
    /**
     * 缓存配置
     */
    public static class Cache {
        /**
         * 是否启用缓存，默认为true
         */
        private boolean enabled = true;
        
        /**
         * 缓存大小，默认为1000
         */
        private int size = 1000;
        
        /**
         * 缓存TTL（毫秒），默认为1小时
         */
        private long ttl = 3600000;
        
        public boolean isEnabled() {
            return enabled;
        }
        
        public void setEnabled(boolean enabled) {
            this.enabled = enabled;
        }
        
        public int getSize() {
            return size;
        }
        
        public void setSize(int size) {
            this.size = size;
        }
        
        public long getTtl() {
            return ttl;
        }
        
        public void setTtl(long ttl) {
            this.ttl = ttl;
        }
    }
    
    /**
     * 验证配置
     */
    public static class Validation {
        /**
         * 是否启用验证，默认为true
         */
        private boolean enabled = true;
        
        /**
         * 是否校验数据长度，默认为true
         */
        private boolean length = true;
        
        /**
         * 是否校验CRC，默认为true
         */
        private boolean crc = true;
        
        public boolean isEnabled() {
            return enabled;
        }
        
        public void setEnabled(boolean enabled) {
            this.enabled = enabled;
        }
        
        public boolean isLength() {
            return length;
        }
        
        public void setLength(boolean length) {
            this.length = length;
        }
        
        public boolean isCrc() {
            return crc;
        }
        
        public void setCrc(boolean crc) {
            this.crc = crc;
        }
    }
    
    /**
     * 插件配置
     */
    public static class Plugin {
        /**
         * 是否启用插件，默认为true
         */
        private boolean enabled = true;
        
        /**
         * 是否自动注册默认插件，默认为true
         */
        private boolean autoRegisterDefaults = true;
        
        public boolean isEnabled() {
            return enabled;
        }
        
        public void setEnabled(boolean enabled) {
            this.enabled = enabled;
        }
        
        public boolean isAutoRegisterDefaults() {
            return autoRegisterDefaults;
        }
        
        public void setAutoRegisterDefaults(boolean autoRegisterDefaults) {
            this.autoRegisterDefaults = autoRegisterDefaults;
        }
    }
    
    /**
     * 版本配置
     */
    public static class Version {
        /**
         * 默认协议版本，默认为HJ212-2017
         */
        private String defaultVersion = "2017";
        
        public String getDefaultVersion() {
            return defaultVersion;
        }
        
        public void setDefaultVersion(String defaultVersion) {
            this.defaultVersion = defaultVersion;
        }
        
        /**
         * 获取协议版本枚举
         * @return 协议版本
         */
        public ProtocolVersion getProtocolVersion() {
            return ProtocolVersion.fromShortName(defaultVersion);
        }
    }
}
